home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Utilities / MView / gxu / d3dx8dbg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  3.1 KB  |  137 lines

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (C) 1999 Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //  File:       d3dx8dbg.cpp
  6. //  Content:    D3DX debugging functions
  7. //
  8. ///////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "pchgxu.h"
  11. #if 0
  12. //#if DBG
  13.  
  14.  
  15. //
  16. // DPF
  17. //
  18.  
  19. void cdecl D3DXDebugPrintf(UINT lvl, LPSTR szFormat, ...)
  20. {
  21.     char strA[256];
  22.     char strB[256];
  23.  
  24. //    if(lvl > (UINT) g_dwDebugLevel)
  25. //        return;
  26.  
  27.     va_list ap;
  28.     va_start(ap, szFormat);
  29.     _vsnprintf(strA, sizeof(strA), szFormat, ap);
  30.     strA[255] = '\0';
  31.     va_end(ap);
  32.  
  33.     _snprintf(strB, sizeof(strB), "D3DX: %s\r\n", strA);
  34.     strB[255] = '\0';
  35.  
  36.     OutputDebugStringA(strB);
  37. }
  38.  
  39.  
  40. //
  41. // DPFHR
  42. //
  43.  
  44. void cdecl D3DXDebugPrintfHR(UINT lvl, HRESULT hr, LPSTR szFormat, ...)
  45. {
  46.     char strA[256];
  47.     char strB[256];
  48.  
  49.     va_list ap;
  50.     va_start(ap, szFormat);
  51.     _vsnprintf(strA, sizeof(strA), szFormat, ap);
  52.     strA[255] = '\0';
  53.     va_end(ap);
  54.  
  55.     D3DXGetErrorStringA(hr, strB, sizeof(strB));
  56.     D3DXDebugPrintf(lvl, "%s: %s", strA, strB);
  57. }
  58.  
  59.  
  60.  
  61. //
  62. // D3DXASSERT
  63. //
  64.  
  65. int WINAPI D3DXDebugAssert(LPCSTR szFile, int nLine, LPCSTR szCondition)
  66. {
  67.     typedef BOOL (*PFNBV)(VOID);
  68.  
  69.     static DWORD dwValue = 0;
  70.     static BOOL bInit = FALSE;
  71.     static PFNBV pIsDebuggerPresent = NULL;
  72.  
  73.     LONG err;
  74.     char str[256];
  75.  
  76.  
  77.     // Print message to debug console
  78.     DPF(0, "Assertion failure! (%s %d): %s", szFile, nLine, szCondition);
  79.  
  80.  
  81.     // Initialize stuff
  82.     if(!bInit)
  83.     {
  84.         HKEY hkey;
  85.         DWORD dwType;
  86.         DWORD cbValue = sizeof(DWORD);
  87.         HINSTANCE hinst;
  88.  
  89.         bInit = TRUE;
  90.  
  91.         // Get IsDebuggerPresent entry point
  92.         if((hinst = (HINSTANCE) GetModuleHandle("kernel32.dll")) ||
  93.            (hinst = (HINSTANCE) LoadLibrary("kernel32.dll")))
  94.         {
  95.             pIsDebuggerPresent = (PFNBV) GetProcAddress(hinst, "IsDebuggerPresent");
  96.         }
  97.  
  98.         // Get debug level from registry
  99.         err = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Direct3D", &hkey);
  100.  
  101.         if(ERROR_SUCCESS != err)
  102.             return 0;
  103.  
  104.         err = RegQueryValueEx(hkey, "D3DX", NULL, &dwType, (LPBYTE) &dwValue, &cbValue);
  105.  
  106.         RegCloseKey(hkey);
  107.  
  108.         if(ERROR_SUCCESS != err || REG_DWORD != dwType || cbValue != sizeof(DWORD))
  109.             return 0;
  110.     }
  111.  
  112.     if(0 == dwValue)
  113.         return 0;
  114.  
  115.     if(1 == dwValue)
  116.         return 1;
  117.  
  118.  
  119.     // Display a message box if no debugger is present
  120.     if((dwValue == 3) || (pIsDebuggerPresent && !pIsDebuggerPresent()))
  121.     {
  122.         _snprintf(str, sizeof(str), "File:\t %s\nLine:\t %d\nAssertion:\t%s\n\nDo you want to invoke the debugger?", szFile, nLine, szCondition);
  123.         err = MessageBox(NULL, str, "D3DX Assertion Failure", MB_SYSTEMMODAL | MB_YESNOCANCEL);
  124.  
  125.         switch(err)
  126.         {
  127.         case IDYES:     return 1;
  128.         case IDNO:      return 0;
  129.         case IDCANCEL:  FatalAppExit(0, "D3DX Assertion Failure.. Application terminated"); return 1;
  130.         }
  131.     }
  132.  
  133.     return 0;
  134. }
  135.  
  136.  
  137. #endif // DBG